package com.fone.player.service;

import android.app.IntentService;
import android.content.Intent;
import android.os.IBinder;

/**
 * Service 容器
 * 
 * @author JasonZue
 * @since 2014-5-19
 */

public class FoneService extends IntentService {

	/** 数据上报 */
	public static final int TYPE_REPORTINFO = 1;
	/** 缓存图片(暂时不确定是否需要) */
	public static final int TYPE_LOADCACHEIMAGE = 2;
	/** 下载APK(升级使用) */
	public static final int TYPE_LOADAPKBYURL = 3;

	public FoneService() {
		super("FoneService");
	}

	public static final String TAG = FoneService.class.getSimpleName();

	public DownloadHandler handler;// 下载handler

	@Override
	public IBinder onBind(Intent intent) {
		return super.onBind(intent);
	}

	@Override
	public void onCreate() {
		super.onCreate();
		handler = new DownloadHandler(FoneService.this);
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		int type = intent.getIntExtra("type", -1);
		switch (type) {
		case TYPE_LOADAPKBYURL:// 下载APK(升级使用)
			String url = intent.getStringExtra("url");
			String showInfo = intent.getStringExtra("showInfo");
			if (handler == null) {
				handler = new DownloadHandler(FoneService.this);
			}
			handler.downApk(url, showInfo);
			break;
		default:
			break;
		}

	}
}
